<template>
    <div style="height: 100%;">
        <navbar :title="lvInfo.lvTitle"></navbar>
        <div style="height: calc(100% - 56px);padding: 56px 0 0 0;">
            <iframe id="iframe" :src="liveUrl" style="height: 100%;" width="100%" scrolling="yes" frameborder="0" allow="microphone; camera" allowfullscreen="true" />
        </div>
        <common-loading :isLoading="isLoading"></common-loading>
    </div>
</template>

<script>
import CommentList from '@/repeatComponents/commentList/CommentList';
import CommonLoading from '@/components/common/loading';
import {appInd} from '../../../config/loginConfig';
export default {
    name: 'LiveDetail',
    components: {
        CommentList,
        CommonLoading
    },
    data() {
        return {
            lvInfo: {},
            liveUrl: '',
            isLiveType: 0,
            isLoading: true
        };
    },
    methods: {
        /**
         * 判断直播地址是否是https，跟自己url地址一致（如果本地用https则直播也需要用https，如果本地用http则直播也需要用http）
         * @param url
         * @returns {string}
         */
        judgmentHttpOrHttps(url) {
            if (url === null || url === '' || url === undefined) return '';
            let https;
            let str = 'https:';
            if (appInd) {
                return url;
            } else {
                if (str === document.location.protocol) {
                    https = true;
                } else {
                    https = false;
                }
            }
            if (https) {
                url = 'https' + url.substring(url.indexOf('://'), url.length);
            } else {
                url = 'http' + url.substring(url.indexOf('://'), url.length);
            }
            return url;
        }
    },
    mounted() {
        this.$axios({
            method: 'GET',
            url: `/app/api/trainee/live/detail/${this.$route.params.lvId}`
        }).then(res => {
            this.lvInfo = res.data;
            let url;
            if (this.lvInfo.lvModeType === 'POLYV') { //保利威视
                this.isLiveType = 1;
                url = this.lvInfo.lvUrl;
            } else {
                url = this.lvInfo.lvStudentJoinUrl;
            }
            this.liveUrl = this.judgmentHttpOrHttps(url);
            let frm = document.getElementById('iframe');
            frm.onload = () => {
                this.isLoading = false;
            };
        });
    }
};
</script>

<style scoped>
    * {
        font-size: 14px;
    }
</style>
